#pragma once

#include "CaelumExternal.h"
#include "Window.h"
#include "BaseException.h"

namespace Caelum {

enum LogLevel 
{ 
	LOGLEVEL_UNDEFINED = 0, 
	LOGLEVEL_INFO,
	LOGLEVEL_NOTICE, 
	LOGLEVEL_WARNING, 
	LOGLEVEL_ERROR, 
	LOGLEVEL_CRITICAL
};

class Logger
{
private:
	
protected:
	LogLevel mMinimumLogLevel;
	bool mCanUploadData;

	std::wstring mFilePath;
	std::wofstream mFile;

	int mBufferCount;
	int mBufferThreshold;
	std::wstring mBuffer;
public:
	Logger() { }
	~Logger() { FlushBuffer(); }
	
	void Initialize(LogLevel MinimumLogLevel = LOGLEVEL_INFO, std::wstring FilePath = L"Caelum.log", int BufferThreshold = 50);

	bool PromptUploadPermission(Window *window = 0);

	bool LogMessage(std::wstring Message, LogLevel Level);
	void FlushBuffer();

	///Does not flush the buffer
	Logger & operator << (const std::wstring &Message);
	///Does not flush the buffer
	Logger & operator << (const int &Message);
	///Does not flush the buffer
	Logger & operator << (const real &Message);

	static inline Logger & Get() {
		static Logger log;
		return log;
	}
};

}
